package com.whitedust.top70;

import com.whitedust.structure.TreeNode;

/**
 *
 * @author A
 * @since 2025/11/11 12:55
 */

public class Top69 {
    int res = 0;

    public int maxDepth(TreeNode root) {
        if (root == null) return 0;
        getMaxDepth(root, 0);
        return res;
    }

    private int getMaxDepth(TreeNode root, int depth) {
        if (root.left == null && root.right == null) {
            res = Math.max(res, depth + 1);
        }
        if (root.left != null) getMaxDepth(root.left, depth + 1);
        if (root.right != null) getMaxDepth(root.right, depth + 1);
        return depth + 1;
    }
}
